<%--
  Created by IntelliJ IDEA.
  User: lake
  Date: 2020/12/16
  Time: 10:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8" %>
<%@ page  import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>$Title$</title>
    <link href="./static/css/bootstrap.min.css" rel="stylesheet"/>
  </head>
  <script type="text/javascript" src="./static/jquery.min.js"></script>
  <script src="./static/js/bootstrap.js"></script>
  <body>
  <div class="modal fade" id="fwqpzModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
       data-backdrop="static"
       data-keyboard="false">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
          </button>
          <h4 class="modal-title" id="myModalLabel">服务器配置向导</h4>
        </div>
        <div class="modal-body">
          <form class="form-horizontal" name="thisform" method="post">
            <div class="form-group">
              <label class="col-sm-2 control-label">驱动类</label>
              <div class="col-sm-10">
                <select id="qdl_input" class="form-control" name="qdl">
                </select>
                <span class="help-block"></span>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">服务器</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="fwq_input" name="fwq"
                       placeholder="请输入服务器IP地址">
                <span class="help-block"></span>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">数据库名</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="sjkmc_input" name="sjkmc"
                       placeholder="请输入新建的数据库名称">
                <span class="help-block"></span>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">用户名</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="yhm_input" name="yhm"
                       placeholder="请输入账户名">
                <span class="help-block"></span>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">密&nbsp;&nbsp;码</label>
              <div class="col-sm-10">
                <input type="password" class="form-control" id="mm_input" name="mm"
                       placeholder="请输入密码">
                <span class="help-block"></span>
              </div>
            </div>
          </form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
          <button type="button" class="btn btn-primary" id="emp_save_btn" onclick="login()">下一步</button>
        </div>
      </div>
    </div>
  </div>
<h1>首页</h1>
  </body>
  <script type="text/javascript">
    $(document).ready(function () {
      $.ajax({
        url: "http://localhost:9999/is_dat",
        type: "get",
        async: false,
        success: function (date) {
          if (date==true){
            alert("有文件")
            //登录
          } else {
            //打开模态框，进行配置文件的设置
            // $("#empAddModal").modal('hide');
            getsblx("#qdl_input");
            $("#fwqpzModal").modal({
              backdrop: "static"
            });
          }
        }
      })
    })

    function getsblx(ele) {
      $.ajax({
        url: 'http://localhost:9999/sbgl/sjkmc/getsjkmc/',
        type: 'get',
        async: false,
        success: function (data) {
          $(ele).empty();
          var options = "";   //字符串拼接
          $(ele).append('<option value="">请选择数据库类型</option>');
          for (var i in data) {  //遍历json数组
            options += "<option value='" + data[i].driverClass + "'>" + data[i].sjkmc + "</option>"
            //     // "<input type='radio' class='roles' name='roles' id='"+data[i].wjdcs+"' value='"+data[i].wjdc+"'>"+data[i].wjdc+"&nbsp;&nbsp;"
          }
          $(ele).append(options);
        }
      })
    }
  function login() {
    var qdl = $("#qdl_input").val()
    <%--var fwq = $("#fwq_input").val()--%>
    <%--var sjkmc = $("#sjkmc_input").val()--%>
    <%--var yhm = $("#yhm_input").val()--%>
    <%--var mm = $("#mm_input").val()--%>
    <%--var jg=<%--%>
                <%--String loginName1=request.getParameter("loginName");--%>
                <%--out.println(loginName1);--%>
             <%--%>;--%>
    <%--alert("jg="+jg);--%>
     document.thisform.submit();
     window.location.href="/jsp/sjklj.jsp"
    <%--var jg ="<% out.println(request.getParameter("loginName"));%>" ;--%>
    <%--el方式：${requestScope.rkey }<br>--%>

  }

    <% String qdl = request.getParameter("qdl");
   String fwq = request.getParameter("fwq");
   String sjkmc = request.getParameter("sjkmc");
   String yhm = request.getParameter("yhm");
   String mm = request.getParameter("mm");
   session.setAttribute("qdl",qdl);
   session.setAttribute("fwq",fwq);
   session.setAttribute("sjkmc",sjkmc);
   session.setAttribute("yhm",yhm);
   session.setAttribute("mm",mm);
   %>
   <%--PreparedStatement ps = null;--%>
   <%--Connection ct = null;--%>
   <%--ResultSet rs = null;--%>
   <%--String url = "jdbc:sqlserver://"+fwq+";databaseName="+sjkmc;--%>
   <%--String user= request.getParameter("yhm");;  //超级管理员--%>
   <%--String password=request.getParameter("mm");;  //密码--%>
   <%--try {--%>
     <%--//1.加载驱动--%>
     <%--Class.forName(qdl);--%>
     <%--System.out.println("加载驱动成功！");--%>
   <%--}catch(Exception e) {--%>
     <%--e.printStackTrace();--%>
     <%--System.out.println("加载驱动失败！");--%>
   <%--}--%>
   <%--try {--%>
     <%--//2.连接--%>
     <%--ct=DriverManager.getConnection( url,user,password);--%>
     <%--System.out.println("连接数据库成功！");--%>
   <%--}catch(Exception e) {--%>
     <%--e.printStackTrace();--%>
     <%--System.out.println("连接数据库失败！");--%>
   <%--}--%>
   <%--out.println("select * from sbxxb"+"<br>");--%>
   <%--/*尝试查询数据库*/--%>
   <%--try{--%>
     <%--Statement stmt = ct.createStatement();--%>
     <%--String sql = "select * from sbxxb";--%>
     <%--// 执行数据库查询语句--%>
     <%--rs = stmt.executeQuery(sql);--%>
     <%--while (rs.next()) {--%>
       <%--String id = rs.getString("gsid");--%>
       <%--String name = rs.getString("sbmc");--%>
       <%--String age = rs.getString("beiz");--%>

<%--//        out.println("gsid:" + id +"\t"+ "sbmc:" + name +"\t"+"beiz:" + age+"<br>");--%>
     <%--}--%>
     <%--if (rs != null) {--%>
       <%--rs.close();--%>
       <%--rs = null;--%>
     <%--}--%>
     <%--if (stmt != null) {--%>
       <%--stmt.close();--%>
       <%--stmt = null;--%>
     <%--}--%>
     <%--if (ct != null) {--%>
       <%--ct.close();--%>
       <%--ct = null;--%>
     <%--}--%>
   <%--}--%>
   <%--catch (SQLException e) {--%>
     <%--e.printStackTrace();--%>
     <%--System.out.println("数据库连接失败");--%>
   <%--}--%>
  </script>

</html>
